<template>
  <div>
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>订单管理</el-breadcrumb-item>
      <el-breadcrumb-item>订单列表</el-breadcrumb-item>
    </el-breadcrumb>
    <el-card>
      <!-- <el-row :gutter="20">
        <el-col :span="8">
          <el-input v-model="getOrdersQuery.query" placeholder="请输入内容">
            <el-button slot="append" @click="getOrderList" icon="el-icon-search"></el-button>
          </el-input>
        </el-col>
      </el-row> -->
      <el-table :data="OrderList" border stripe>
        <el-table-column type="index" label="#"></el-table-column>
        <el-table-column prop="order_number" label="订单编号" ></el-table-column>
        <el-table-column prop="order_price" label="订单价格" width="120px"></el-table-column>
        <el-table-column prop="pay_status" label="是否付款" width="120px">
          <template slot-scope="scope">
            <el-tag type="success" v-if="scope.row.pay_status=== '1' ">已付款</el-tag>
            <el-tag type="danger" v-else>未付款</el-tag>
          </template>
        </el-table-column>
        <el-table-column prop="is_send" label="是否配送" width="120px"></el-table-column>
        <el-table-column label="下单时间" width="140px">
          <template slot-scope="scope">{{scope.row.create_time | time}}</template>
        </el-table-column>
        <el-table-column label="操作" width="90px">
          <template slot-scope="scope">
            <el-tooltip class="item" effect="dark" :enterable="false" content="更改收货地址" placement="top">
              <el-button @click="showAddress" type="primary" size="mini" icon="el-icon-edit"></el-button>
            </el-tooltip>
          </template>
        </el-table-column>
      </el-table>
      <!-- 分页区域 -->
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="getOrdersQuery.pagenum"
        :page-sizes="[5, 10, 15, 20]"
        :page-size="getOrdersQuery.pagesize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
      ></el-pagination>
      <!-- 修改地址对话框 -->
      <el-dialog title :visible.sync="addressVisible" width="50%" @close="closeVisible">
        <el-form
          label-position="top"
          :model="addressForm"
          :rules="addressFormRules"
          ref="addressFormRef"
          label-width="80px"
        >
          <el-form-item label="省市区/县" prop="address1">
            <el-cascader v-model="addressForm.addressMain" :options="cityData" :props="cityProps"></el-cascader>
          </el-form-item>
          <el-form-item label="详细地址" prop="addressCare">
            <el-input v-model="addressForm.addressCare"></el-input>
          </el-form-item>
        </el-form>

        <span slot="footer">
          <el-button @click="addressVisible = false">取 消</el-button>
          <el-button type="primary" @click="addressVisible = false">确 定</el-button>
        </span>
      </el-dialog>
      <!-- 展示物流进度的对话框 -->
    </el-card>
  </div>
</template>
<script>
import cityData from './citydata.js'
export default {
  data () {
    return {
      getOrdersQuery: {
        query: '',
        pagenum: 1,
        pagesize: 10
      },
      total: 0,
      OrderList: [],
      addressVisible: false,
      addressForm: {
        addressMain: [],
        addressCare: ''
      },
      addressFormRules: {
        address1: [
          { required: true, message: '请选择省市区/县', trigger: 'blur' }
        ],
        addressCare: [
          { required: true, message: '请填写详细地址', trigger: 'blur' }
        ]
      },
      // 省市区县城市数据
      cityData: cityData,
      cityProps: {
        expandTrigger: 'hover',
        label: 'label',
        value: 'value',
        children: 'children'
      },
      progressInfo: [],
      progressVisible: false
    }
  },
  created () {
    this.getOrderList()
  },
  methods: {
    async getOrderList () {
      // console.log(this.getOrdersQuery.query)

      const { data: res } = await this.$http.get(`orders`, {
        params: this.getOrdersQuery
      })
      if (res.meta.status !== 200) {
        return this.$message({
          message: '获取订单列表失败',
          type: 'error'
        })
      }
      //   console.log(res.data)
      this.OrderList = res.data.goods
      this.total = res.data.total
    },
    handleSizeChange (newSize) {
      this.getOrdersQuery.pagesize = newSize
      this.getOrderList()
    },
    handleCurrentChange (newPage) {
      this.getOrdersQuery.pagenum = newPage
      this.getOrderList()
    },
    showAddress () {
      this.addressVisible = true
    },
    closeVisible () {
      this.$refs.addressFormRef.resetFields()
    }
    // 未提供修改接口
    // addressEdit () {
    //   this.$refs.addressFormRef.validate(async valid => {
    //     if (!valid) {
    //       return this.$message({
    //         message: '请填写正确的信息',
    //         type: 'info'
    //       })
    //     }
    //     const { data: res } = await this.$http.put(``)
    //   })
    // }
    // 展示物流信息对话框并获取物流信息
    // async showProgressBox () {
    //   const { data: res } = await this.$http.get('/kuaidi/804909574412544580')

    //   if (res.meta.status !== 200) {
    //     return this.$message.error('获取物流进度失败！')
    //   }

    //   this.progressInfo = res.data

    //   this.progressVisible = true
    //   //   console.log(this.progressInfo)
    // }
  }
}
</script>
<style lang="less" scoped>
// 导入时间线组件的样式
@import '../../plugins/timeline/timeline.css';
@import '../../plugins/timeline-item/timeline-item.css';
.el-cascader {
  width: 100%;
}
</style>
